package org.example.springboot.mapper;

import org.apache.ibatis.annotations.*;
import org.example.springboot.entity.Classification;

import java.util.List;

@Mapper
public interface ClassificationMapper {

    @Select("SELECT * FROM classification WHERE course LIKE CONCAT ('%', #{course}, '%') LIMIT #{offset}, #{pageSize} ")
    List<Classification> getClassificationsByPage(@Param("pageSize") int pageSize, @Param("offset") int offset, @Param("course") String course);

    @Select("SELECT COUNT(*) FROM classification WHERE course LIKE CONCAT ('%', #{course}, '%')")
    Integer getClassificationCount(@Param("course") String course);

    @Delete("DELETE FROM classification WHERE course = #{course}")
    void deleteClassificationByCourse(@Param("course") String course);

    @Insert("INSERT INTO classification (avatar,course,category) " +
            "VALUES (#{avatar}, #{course},#{category})")
    void insertClassification(Classification classification);

    @Select("SELECT * FROM classification WHERE course = #{course}")
    Classification selectByCourse(String course);

    @Update("UPDATE classification SET avatar = #{avatar}, course = #{course},category = #{category} WHERE course = #{course}")
    void updateClassification(Classification classification);

    @Select("SELECT * FROM classification")
    List<Classification> selectAll();

}
